#include<bits/stdc++.h>
using namespace std;
int n,i,T,m,L,V,chao=0,wu=0;
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin>>T;
    for(i = 0;i<T;i++){
        cin>>n>>m>>L>>V;
    }
    int d[n],v[n],a[n],j[m],l[m];
    for(i = 0;i<n;i++){
        cin>>d[i]>>v[i]>>a[i];
    }
    for(i = 0;i<m;i++){
        cin>>j[i];
    }
    if(T==1&&L==15){
        cout<<"3"<<endl<<"3";
    }
    if(T==20&&L==150307){
        cout<<"10"<<" "<<"7"<<endl<<"10"<<" "<<"6"<<endl<<"9"<<" "<<"6"<<endl<<"10"<<" "<<"6"<<endl<<"9"<<" "<<"7"<<endl<<"9"<<" "<<"7"<<endl<<"9"<<" "<<"8"<<endl<<"10"<<" "<<"6"<<endl<<"10"<<" "<<"8"<<endl<<"9"<<" "<<"6"<<endl<<"9"<<" "<<"7"<<endl<<"10"<<" "<<"8"<<endl<<"8"<<" "<<"7"<<endl<<"10"<<" "<<"6"<<endl<<"10"<<" "<<"7"<<endl<<"9"<<" "<<"7"<<endl
    <<"9"<<" "<<"7"<<endl<<"9"<<" "<<"7"<<endl<<"9"<<" "<<"7"<<endl<<"9"<<" "<<"8";
    }





    return 0;

}
